<?php

class m120601_145641_update_leave extends EDbMigration {

	public function safeUp() {
		$this->alterColumn('leaves', 'status', 'varchar(32)');

		$columns = array('status'=>Leave::STATUS_APPROVED_MANAGEMENT);
		$conditions = array('and', "status = 'Approved'");
		$this->update('leaves', $columns, $conditions);


		$columns = array('status'=>Leave::STATUS_REJECTED_MANAGEMENT);
		$conditions = array('and', "status = 'Rejected'");
		$this->update('leaves', $columns, $conditions);
	}

	public function safeDown() {
		$columns = array('status'=>'Rejected');
		$conditions = array(
			'and',
			"status = '" . Leave::STATUS_REJECTED_MANAGEMENT . "'"
		);
		$this->update('leaves', $columns, $conditions);

		$columns = array('status'=>'Approved');
		$conditions = array(
			'and',
			"status = '" . Leave::STATUS_APPROVED_MANAGEMENT . "'"
		);
		$this->update('leaves', $columns, $conditions);

		$this->alterColumn('leaves', 'status', 'varchar(8)');
	}

}